package com.yzr.common.thread;

import java.util.concurrent.atomic.AtomicMarkableReference;

/**
 * @author yx-0173
 */
public class AtomicMarkableReferenceTest {

    public static class Demo {

        private String name;
        private Integer age;


        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getAge() {
            return age;
        }

        public void setAge(Integer age) {
            this.age = age;
        }

        @Override
        public String toString() {
            return "Demo{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    '}';
        }
    }

    static Demo demo = new Demo();
    static boolean mark = true;
    static AtomicMarkableReference<Demo> markReference = new AtomicMarkableReference<>(demo, mark);

    public static void main(String[] args) {
        demo.setAge(1);
        mark = false;
        boolean b = markReference.compareAndSet(demo, demo, mark, mark);
        System.out.println(b);
    }
}
